﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a tool for optical character verification.</summary>
	// Token: 0x02000056 RID: 86
	[Serializable]
	public class HOCV : HHandle, ISerializable, ICloneable
	{
		// Token: 0x06000C64 RID: 3172 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCV() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000C65 RID: 3173 RVA: 0x0004E4F5 File Offset: 0x0004C6F5
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCV(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000C66 RID: 3174 RVA: 0x0004E504 File Offset: 0x0004C704
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCV(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000C67 RID: 3175 RVA: 0x0004E513 File Offset: 0x0004C713
		private void AssertSemType()
		{
			base.AssertSemType("ocv");
		}

		// Token: 0x06000C68 RID: 3176 RVA: 0x0004E520 File Offset: 0x0004C720
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HOCV obj)
		{
			obj = new HOCV(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000C69 RID: 3177 RVA: 0x0004E538 File Offset: 0x0004C738
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HOCV[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HOCV[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HOCV(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Reading an OCV tool from file.
		///   Modified instance represents: Handle of read OCV tool.
		/// </summary>
		/// <param name="fileName">Name of the file which has to be read. Default: "test_ocv"</param>
		// Token: 0x06000C6A RID: 3178 RVA: 0x0004E5A8 File Offset: 0x0004C7A8
		public HOCV(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(642);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new OCV tool based on gray value projections.
		///   Modified instance represents: Handle of the created OCV tool.
		/// </summary>
		/// <param name="patternNames">List of names for patterns to be trained. Default: "a"</param>
		// Token: 0x06000C6B RID: 3179 RVA: 0x0004E5F4 File Offset: 0x0004C7F4
		public HOCV(HTuple patternNames)
		{
			IntPtr proc = HalconAPI.PreCall(646);
			HalconAPI.Store(proc, 0, patternNames);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(patternNames);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x06000C6C RID: 3180 RVA: 0x0004E648 File Offset: 0x0004C848
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeOcv();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x06000C6D RID: 3181 RVA: 0x0004E680 File Offset: 0x0004C880
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCV(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeOcv(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x06000C6E RID: 3182 RVA: 0x0004E6C0 File Offset: 0x0004C8C0
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeOcv();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x06000C6F RID: 3183 RVA: 0x0004E6D4 File Offset: 0x0004C8D4
		public new static HOCV Deserialize(Stream stream)
		{
			HOCV hocv = new HOCV();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			hocv.DeserializeOcv(hserializedItem);
			hserializedItem.Dispose();
			return hocv;
		}

		// Token: 0x06000C70 RID: 3184 RVA: 0x0004E6FA File Offset: 0x0004C8FA
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x06000C71 RID: 3185 RVA: 0x0004E704 File Offset: 0x0004C904
		public new HOCV Clone()
		{
			HSerializedItem hserializedItem = this.SerializeOcv();
			HOCV hocv = new HOCV();
			hocv.DeserializeOcv(hserializedItem);
			hserializedItem.Dispose();
			return hocv;
		}

		/// <summary>
		///   Verification of a pattern using an OCV tool.
		///   Instance represents: Handle of the OCV tool.
		/// </summary>
		/// <param name="pattern">Characters to be verified.</param>
		/// <param name="patternName">Name of the character. Default: "a"</param>
		/// <param name="adaptPos">Adaption to vertical and horizontal translation. Default: "true"</param>
		/// <param name="adaptSize">Adaption to vertical and horizontal scaling of the size. Default: "true"</param>
		/// <param name="adaptAngle">Adaption to changes of the orientation (not implemented). Default: "false"</param>
		/// <param name="adaptGray">Adaption to additive and scaling gray value changes. Default: "true"</param>
		/// <param name="threshold">Minimum difference between objects. Default: 10</param>
		/// <returns>Evaluation of the character.</returns>
		// Token: 0x06000C72 RID: 3186 RVA: 0x0004E72C File Offset: 0x0004C92C
		public HTuple DoOcvSimple(HImage pattern, HTuple patternName, string adaptPos, string adaptSize, string adaptAngle, string adaptGray, double threshold)
		{
			IntPtr proc = HalconAPI.PreCall(638);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, pattern);
			HalconAPI.Store(proc, 1, patternName);
			HalconAPI.StoreS(proc, 2, adaptPos);
			HalconAPI.StoreS(proc, 3, adaptSize);
			HalconAPI.StoreS(proc, 4, adaptAngle);
			HalconAPI.StoreS(proc, 5, adaptGray);
			HalconAPI.StoreD(proc, 6, threshold);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(patternName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.DOUBLE, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(pattern);
			return result;
		}

		/// <summary>
		///   Verification of a pattern using an OCV tool.
		///   Instance represents: Handle of the OCV tool.
		/// </summary>
		/// <param name="pattern">Characters to be verified.</param>
		/// <param name="patternName">Name of the character. Default: "a"</param>
		/// <param name="adaptPos">Adaption to vertical and horizontal translation. Default: "true"</param>
		/// <param name="adaptSize">Adaption to vertical and horizontal scaling of the size. Default: "true"</param>
		/// <param name="adaptAngle">Adaption to changes of the orientation (not implemented). Default: "false"</param>
		/// <param name="adaptGray">Adaption to additive and scaling gray value changes. Default: "true"</param>
		/// <param name="threshold">Minimum difference between objects. Default: 10</param>
		/// <returns>Evaluation of the character.</returns>
		// Token: 0x06000C73 RID: 3187 RVA: 0x0004E7C0 File Offset: 0x0004C9C0
		public double DoOcvSimple(HImage pattern, string patternName, string adaptPos, string adaptSize, string adaptAngle, string adaptGray, double threshold)
		{
			IntPtr proc = HalconAPI.PreCall(638);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, pattern);
			HalconAPI.StoreS(proc, 1, patternName);
			HalconAPI.StoreS(proc, 2, adaptPos);
			HalconAPI.StoreS(proc, 3, adaptSize);
			HalconAPI.StoreS(proc, 4, adaptAngle);
			HalconAPI.StoreS(proc, 5, adaptGray);
			HalconAPI.StoreD(proc, 6, threshold);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			double result;
			num = HalconAPI.LoadD(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(pattern);
			return result;
		}

		/// <summary>
		///   Training of an OCV tool.
		///   Instance represents: Handle of the OCV tool to be trained.
		/// </summary>
		/// <param name="pattern">Pattern to be trained.</param>
		/// <param name="name">Name(s) of the object(s) to analyse. Default: "a"</param>
		/// <param name="mode">Mode for training (only one mode implemented). Default: "single"</param>
		// Token: 0x06000C74 RID: 3188 RVA: 0x0004E84C File Offset: 0x0004CA4C
		public void TraindOcvProj(HImage pattern, HTuple name, string mode)
		{
			IntPtr proc = HalconAPI.PreCall(639);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, pattern);
			HalconAPI.Store(proc, 1, name);
			HalconAPI.StoreS(proc, 2, mode);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(name);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(pattern);
		}

		/// <summary>
		///   Training of an OCV tool.
		///   Instance represents: Handle of the OCV tool to be trained.
		/// </summary>
		/// <param name="pattern">Pattern to be trained.</param>
		/// <param name="name">Name(s) of the object(s) to analyse. Default: "a"</param>
		/// <param name="mode">Mode for training (only one mode implemented). Default: "single"</param>
		// Token: 0x06000C75 RID: 3189 RVA: 0x0004E8A4 File Offset: 0x0004CAA4
		public void TraindOcvProj(HImage pattern, string name, string mode)
		{
			IntPtr proc = HalconAPI.PreCall(639);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, pattern);
			HalconAPI.StoreS(proc, 1, name);
			HalconAPI.StoreS(proc, 2, mode);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(pattern);
		}

		/// <summary>
		///   Deserialize a serialized OCV tool.
		///   Modified instance represents: Handle of the OCV tool.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x06000C76 RID: 3190 RVA: 0x0004E8F8 File Offset: 0x0004CAF8
		public void DeserializeOcv(HSerializedItem serializedItemHandle)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(640);
			HalconAPI.Store(proc, 0, serializedItemHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Serialize an OCV tool.
		///   Instance represents: Handle of the OCV tool.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x06000C77 RID: 3191 RVA: 0x0004E94C File Offset: 0x0004CB4C
		public HSerializedItem SerializeOcv()
		{
			IntPtr proc = HalconAPI.PreCall(641);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Reading an OCV tool from file.
		///   Modified instance represents: Handle of read OCV tool.
		/// </summary>
		/// <param name="fileName">Name of the file which has to be read. Default: "test_ocv"</param>
		// Token: 0x06000C78 RID: 3192 RVA: 0x0004E994 File Offset: 0x0004CB94
		public void ReadOcv(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(642);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Saving an OCV tool to file.
		///   Instance represents: Handle of the OCV tool to be written.
		/// </summary>
		/// <param name="fileName">Name of the file where the tool has to be saved. Default: "test_ocv"</param>
		// Token: 0x06000C79 RID: 3193 RVA: 0x0004E9E0 File Offset: 0x0004CBE0
		public void WriteOcv(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(643);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Clear an OCV tool.
		///   Instance represents: Handle of the OCV tool which has to be freed.
		/// </summary>
		// Token: 0x06000C7A RID: 3194 RVA: 0x0004EA1C File Offset: 0x0004CC1C
		public void CloseOcv()
		{
			IntPtr proc = HalconAPI.PreCall(645);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new OCV tool based on gray value projections.
		///   Modified instance represents: Handle of the created OCV tool.
		/// </summary>
		/// <param name="patternNames">List of names for patterns to be trained. Default: "a"</param>
		// Token: 0x06000C7B RID: 3195 RVA: 0x0004EA50 File Offset: 0x0004CC50
		public void CreateOcvProj(HTuple patternNames)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(646);
			HalconAPI.Store(proc, 0, patternNames);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(patternNames);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new OCV tool based on gray value projections.
		///   Modified instance represents: Handle of the created OCV tool.
		/// </summary>
		/// <param name="patternNames">List of names for patterns to be trained. Default: "a"</param>
		// Token: 0x06000C7C RID: 3196 RVA: 0x0004EAA4 File Offset: 0x0004CCA4
		public void CreateOcvProj(string patternNames)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(646);
			HalconAPI.StoreS(proc, 0, patternNames);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
